﻿using System;
using Bonesoft.Forms.Fiscal;
using Business;
using Business.Entity.Contabil.Pessoa.SubClass.Usuario.ClassesRelacionadas;
using Business.Entity.Fiscal;
using Business.Forms;
using Business.Seguranca;
using Business.Validation;
using DevExpress.XtraEditors;

namespace Bonesoft.Lists.Fiscal
{
    public partial class ListNotaFiscalEntrada : ListDefault,IForm
    {
        public ListNotaFiscalEntrada()
        {
            InitializeComponent();
            Reload();
        }

        private IForm GetFormEdit()
        {
            if (FormEdit == null)
            {
                FormEdit = new FormNotaFiscalEntrada();
            }
            return FormEdit;
        }
        public object Save()
        {
            throw new NotImplementedException();
        }

        public void Update(object entity)
        {
            GetFormEdit().Update(entity);
        }

        public bool Delete(object entity)
        {
            GetFormEdit().Delete(entity);
            return false;
        }

        public object CurrentObject
        {
            get
            {
                return notaFiscalBindingSource.Current;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public PermissaoForm Permissao
        {
            get
            {
                return SegurancaUtils.GetPermissaoForm(Name);
            }
        }

        public EntityValidationResult Validate()
        {
            throw new NotImplementedException();
        }

        public void Reload()
        {
            notaFiscalBindingSource.DataSource = NotaFiscalRepository.GetQueryOver()
                .Where(nota => nota.Entrada == true).List<NotaFiscal>();
        }

        public void Cancel()
        {
            throw new NotImplementedException();
        }

        public object New()
        {
            var nf = GetFormEdit().New();
            if (nf != null)
            {
                notaFiscalBindingSource.Add(nf);
            }
            return nf;
        }

        public XtraForm Form
        {
            get
            {
                return this;
            }
        }

        public FormState FormState { get; set; }
    }
}
